#include <dbg.h>

#include <cassert>
using namespace std;

class Solution {
public:
    int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int minutes) {
        vector<int> sum(2, 0);  // 0: 不生气, 1: 生气
        int maxSum1 = 0;
        for (int i = 0; i < customers.size(); ++i) {
            sum[grumpy[i]] += customers[i];  // 生气的累加, 不生气的累加
            if (i < minutes - 1) {
                continue;
            }
            maxSum1 = max(maxSum1, sum[1]);  // 生气的最大值
            sum[1] -= grumpy[i - minutes + 1] ? customers[i - minutes + 1] : 0;
        }
        return sum[0] + maxSum1;
    }
};

int main() {
    Solution s;

    vector<int> customers1 = {1, 0, 1, 2, 1, 1, 7, 5};
    vector<int> customers2 = {1};
    vector<int> grumpy1 = {0, 1, 0, 1, 0, 1, 0, 1};
    vector<int> grumpy2 = {0};
    int minutes1 = 3;
    int minutes2 = 1;

    assert(s.maxSatisfied(customers1, grumpy1, minutes1) == 16);
    assert(s.maxSatisfied(customers2, grumpy2, minutes2) == 1);

    return 0;
}